using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
using Utility;

public partial class User_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {          
            LoadData();
           // LoadData_menu();
        }  
    }
    private void LoadData()
    {

        Pager.PageSize = 5;
        Criteria c = new Criteria();
        int total = 0;
        tbSanPhamEntities.tbSanPhanEntitiesCollection dd_Collection =
            tbSanPhamBUS.Get(c.Criter, Pager.CurrentIndex, Pager.PageSize,
           tbSanPhamEntities.tbSanPhanEntitiesColumns.MaSP.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = dd_Collection;
        Repeater1.DataBind();
        Pager.ItemCount = total;
        if (total <= Pager.PageSize)
            Pager.Visible = false;
    }
    protected void Pager_Command(object sender, CommandEventArgs e)
    {
        Pager.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        LoadData();
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
            e.Item.ItemType == ListItemType.Item)
        {
            tbSanPhamEntities sp = (tbSanPhamEntities)e.Item.DataItem;
            HyperLink hyp_sp = (HyperLink)e.Item.FindControl("hyp_sp");
            Literal lit_idsp = (Literal)e.Item.FindControl("lit_idsp");
            Image img_hinhanh = (Image)e.Item.FindControl("img_hinhanh");
            //Literal lit_mota = (Literal)e.Item.FindControl("lit_mota");

            hyp_sp.Text = sp.TenSP;
            lit_idsp.Text = sp.MaSP.ToString();
            //lit_mota.Text = sp.MoTaSP.Substring(0,40) + "...";
           

            int IDH = tbHinhAnhBUS.imageFirst(int.Parse(sp.MaSP.ToString()));
            tbHinhAnhEntities hh = tbHinhAnhBUS.GetByID(IDH);

            img_hinhanh.ImageUrl = "~/Photos/Thumb/" + hh.HinhAnh.ToString();
            hyp_sp.NavigateUrl = "ChiTietSanPham.aspx?id= " + sp.MaSP.ToString();          
        }

    }

    //private void LoadData_menu()
    //{

    //    //tbLoaiSP loaisp = tbLoaiSPBUS.GetByID(int.Parse(Request.QueryString["id"]));
    //    tbLoaiSP.tbLoaiSPCollections loai_collection = tbLoaiSPBUS.GetAll();
    //    Repeater2.DataSource = loai_collection;
    //    Repeater2.DataBind();
    //}
    //protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
    //{
    //    if (e.Item.ItemType == ListItemType.Item
    //          || e.Item.ItemType == ListItemType.AlternatingItem)
    //    {
    //        tbLoaiSP loai = (tbLoaiSP)e.Item.DataItem;
    //        HyperLink lb_Name = (HyperLink)e.Item.FindControl("lb_Name");
    //        lb_Name.Text = loai.TenLoai;
    //        // hpl_Edit.NavigateUrl = "TTGiaoDichUpdate.aspx?id=" + gd_tbl.IDGD.ToString();
    //        lb_Name.NavigateUrl = "SanPhamTheoLoai.aspx?id=" + loai.IDL.ToString();
    //    }
    //}
   
}
